package part16;

/**
 * @author wcj
 * @Date 2021/5/31 17:08
 * @Version 1.0
 */
public class Part167 {

    private static int size = 10;

    /**
     * 数组的使用，结合生成器
     *
     * @param c
     */
    public static void test(Class<?> c) {
        for (Class<?> aClass : c.getClasses()) {
            System.out.println(aClass.getSimpleName());
            try {
                Generator<?> generator = (Generator<?>) aClass.newInstance();
                for (int i = 0; i < size; i++) {
                    System.out.println(generator.next() + "");
                }
            } catch (Exception e) {
                throw new RuntimeException(e);
            }

        }
    }

    public static void main(String[] args) {
        test(CountingGenerator.class);
    }
}

interface Generator<T> {
    T next();
}

class CountingGenerator {
    public static class Boolean implements Generator<java.lang.Boolean> {

        private boolean value = false;

        @Override
        public java.lang.Boolean next() {
            return value;
        }
    }

    public static class Byte implements Generator<java.lang.Byte> {
        private byte value = 0;

        @Override
        public java.lang.Byte next() {
            return value++;
        }
    }

    static char[] chars = ("dabfqwiqfnqwifuqwfqifujnqw" + "DAFIQOFNQFN").toCharArray();

    public static class Character implements Generator<java.lang.Character> {
        int index = -1;

        @Override
        public java.lang.Character next() {
            return chars[++index];
        }
    }

    public static class String implements Generator<java.lang.String> {
        private int length = 7;
        Generator<java.lang.Character> cg = new Character();

        public String() {
        }

        public String(int length) {
            this.length = length;
        }

        @Override
        public java.lang.String next() {
            char[] chars = new char[length++];
            for (int i = 0; i < length; i++) {
                chars[i] = cg.next();
            }
            return new java.lang.String(chars);
        }
    }

    public static class Shorts implements Generator<java.lang.Short> {
        private short value = 0;

        @Override
        public Short next() {
            return value++;
        }
    }

    public static class Integer implements Generator<java.lang.Integer> {

        private int value = 0;

        @Override
        public java.lang.Integer next() {
            return value++;
        }
    }

    public static class Long implements Generator<java.lang.Long> {

        private long value = 0;

        @Override
        public java.lang.Long next() {
            return value++;
        }
    }

    public static class Float implements Generator<java.lang.Float> {
        private float value = 0;

        @Override
        public java.lang.Float next() {
            return value + 1.0f;
        }
    }

    public static class Double implements Generator<java.lang.Double> {
        private double value = 0;

        @Override
        public java.lang.Double next() {
            return value + 1.0;
        }
    }
}
